package ex.array;

import java.util.ArrayList;
import java.util.List;

/**
 * List集合toArray方法的三种使用方式
 */
public class ToArrayDemo {
    public static void main(String[] args) {
        List<String> sites = new ArrayList<>();
        sites.add("google");
        sites.add("baidu");
        sites.add("sina");
        sites.add("163");

        String[] arr = new String[sites.size()];
        sites.toArray(arr);

        System.out.println("Array:");
        for (String item : arr) {
            System.out.print(item + ",");
        }
        System.out.println();

        System.out.println("Array1:");
        String[] strings = sites.toArray(new String[0]);
        for (String item : strings) {
            System.out.print(item + ",");
        }
        System.out.println();

        System.out.println("Array2:");
        Object[] objects = sites.toArray();
        for (Object item : objects) {
            System.out.print(item + ",");
        }
        System.out.println();
    }
}
